# coding=utf-8

import time
import random
import requests
import threading
from multiprocessing import Process


def Process_Program(index):
    time.sleep(random.randint(1, 3))
    print('进程{}'.format(index))


def Thread_Program(index):
    time.sleep(random.randint(1, 3))
    print('线程{}'.format(index))


if __name__ == '__main__':
    start_time = time.time()

    process_list = []
    for i in range(5):
        process_list.append(Process(target=Process_Program, args=(i,)))

    for p in process_list:
        p.start()
    for p in process_list:
        p.join()

    """
    进程0
进程2
进程4
进程1
进程3
程序共耗时3.88S"""

    # threads = []
    # for k in range(5):
    #     threads.append(threading.Thread(target=Thread_Program, args=(k,)))
    #
    # print("Go!")
    # for t in threads:
    #     t.start()
    # for t in threads:
    #     t.join()
    #
    # print('finish')
    end_time = time.time()
    print('程序共耗时{:.2f}S'.format(end_time - start_time))
    """
Go!
线程3
线程1
线程4
线程0
线程2
finish
程序共耗时3.00S"""
